/**
 * 
 */
package idv.takeshi.software.productline.bookstore.presentation.web.function;

import org.apache.commons.lang.Validate;

import idv.takeshi.software.productline.bookstore.domain.model.book.InventoryStatus;
import idv.takeshi.software.productline.bookstore.domain.model.order.Atm;
import idv.takeshi.software.productline.bookstore.domain.model.order.CashInConvenientStore;
import idv.takeshi.software.productline.bookstore.domain.model.order.CreditCard;
import idv.takeshi.software.productline.bookstore.domain.model.order.DuplicateInvoice;
import idv.takeshi.software.productline.bookstore.domain.model.order.DuplicateInvoiceWithCashier;
import idv.takeshi.software.productline.bookstore.domain.model.order.Invoice;
import idv.takeshi.software.productline.bookstore.domain.model.order.OrderStatus;
import idv.takeshi.software.productline.bookstore.domain.model.order.Payment;
import idv.takeshi.software.productline.bookstore.domain.model.order.PostalOrder;

/**
 * A class to rpovide EL-based convenient functions.
 * @author takeshi
 *
 */
public class Functions {
	
	private Functions(){}
	
	/**
	 * Get message code by given inventory status enum.
	 * @param status
	 * @return
	 */
	public static final String getInventoryStatusMessageCode(InventoryStatus status){
		Validate.notNull(status, "inventory status shall always not be null/empty");
		
		String code = null;
		
		switch(status){
		
		case ACTIVE:
			code = "inventory.status.active";
			break;
		case INACTIVE:
			code = "inventory.status.inactive";
			break;
		case OUT_OF_PRINT:
			code = "inventory.status.outOfPrint";
			break;
		case REPLENISH_AFTER_ORDERED:
			code = "inventory.status.replenishAfterOrdered";
			break;
		default:	
			throw new RuntimeException("undefined inventory status:" + status);
		}
		
		return code;
	}
	
	/**
	 * Get message code by given payment.
	 * @param payment
	 * @return
	 */
	public static final String getPaymentMessageCode(Payment payment){
		Validate.notNull(payment, "payment shall always not be null");
		String code = null;
		
		if(payment instanceof CashInConvenientStore){
			code = "payment.cashInConvenientStore";
		} else if(payment instanceof CreditCard){
			code = "payment.creditCard";
		} else if(payment instanceof Atm){
			code = "payment.atm";
		} else if(payment instanceof PostalOrder){
			code = "payment.postalOrder";
		} else{
			throw new RuntimeException("undefied payment type:" + payment);
		}
		
		return code;
	}
	
	/**
	 * Get message code by given invoice.
	 * @param invoice
	 * @return
	 */
	public static final String getInvoiceMessageCode(Invoice invoice){
		Validate.notNull(invoice, "invoice shall always not be null");
		String code = null;
		
		if(invoice instanceof DuplicateInvoice){
			code = "invoice.duplicateInvoice";
		} else if(invoice instanceof DuplicateInvoiceWithCashier){
			code = "invoice.duplicateInvoiceWithCashier";
		} else if(invoice instanceof Invoice){
			code = "invoice.invoice";
		} else{
			throw new RuntimeException("undefined invoice type:" + invoice);
		}
		
		return code;
	}
	
	/**
	 * @param status
	 * @return
	 */
	public static final String getOrderStatusMessageCode(OrderStatus status){
		Validate.notNull(status, "order status shall always not be null/empty");
		
		String code = null;
		
		switch(status){
		
		case NEW:
			code = "order.status.new";
			break;
		case WAIT_FOR_REPLENISHMENT:
			code = "order.status.waitForReplenishment";
			break;
		case UNDER_PROCESSING:
			code = "order.status.underProcessing";
			break;
		case UNDER_DELIVERY:
			code = "order.status.underDelivery";
			break;
		case RECEIVED:
			code = "order.status.received";
			break;
		case IN_CONVENIENT_STORE:
			code = "order.status.inConvenientStore";
			break;
		case CLOSE:
			code = "order.status.close";
			break;
		case CANCEL:
			code = "order.status.cancel";
			break;
		default:	
			throw new RuntimeException("undefined order status:" + status);
		}
		
		return code;
	}

}
